﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Text;
using WindowsPhoneAudioStreaming.MockRadioStation.Logic;

namespace WindowsPhoneAudioStreaming.MockRadioStation
{
    public partial class Programs : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MockRadioStationLogic logicClient = new MockRadioStationLogic();
            var programs = logicClient.GetPrograms();
            logicClient.Close();

            // Create a new XmlTextWriter instance
            XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
            
            // start writing!
            writer.WriteStartDocument();
            writer.WriteStartElement("Programs");

            foreach (var program in programs)
            {
                // Creating the <browserInfo> element
                writer.WriteStartElement("Program");
                writer.WriteElementString("Name", program.Name);
                writer.WriteElementString("Description", program.Description);
                writer.WriteElementString("Presenters", program.Presenters);
                writer.WriteElementString("StartTime", program.StartTime.ToString());
                writer.WriteElementString("EndTime", program.EndTime.ToString());
                writer.WriteElementString("AssociatedPodcastUrl", program.AssociatedPodcastUrl);
                writer.WriteElementString("AssociatedImageUrl", program.AssociatedImageUrl);
                writer.WriteEndElement();
            }


            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Close();
        }
    }
}